<template>
    <div class="api">正在加载中...</div>
</template>


<script>
import { mapState, mapMutations } from 'vuex';
import {ApiLogin} from "../../api/api/Api";
import util from '@/libs/util';
export default {
  name: 'index',
  computed: {
    ...mapState('home/site', [
      "site",
      "openSite"
    ])
  },
  data () {
    return {
    }
  },
  created () {
    let user = this.$route.query.user || "";
    let nonce = this.$route.query.nonce || "";
    let timestamp =  this.$route.query.timestamp || "";
    let sign = this.$route.query.sign || "";
    ApiLogin({
        user : user,
      nonce : nonce,
      timestamp : timestamp,
      sign : sign
    }).then(res=>{
        if(res.code == 200) {
          let expires = this.getExpiresTime(res.data.expires_time);
          // 记录用户登陆信息
          util.cookies.set('system_uuid', res.data.user_info.id, {
            expires: expires
          });
          //用户token
          util.cookies.set('system_token', res.data.token, {
            expires: expires
          });
          //过期时间
          util.cookies.set('system_expires_time', res.data.expires_time, {
            expires: expires
          });

          this.$store.dispatch('system/menu/set', res.data.menus);
          this.$store.dispatch('system/user/set', res.data.user_info);
          this.$store.dispatch('system/user/setpaths', res.data.paths);
          this.$router.replace({path: '/system/index'});
        } else {
          this.$alert(res.msg);
        }
    })
  },
  methods: {
    getExpiresTime (expiresTime) {
      let nowTimeNum = Math.round(new Date() / 1000);
      let expiresTimeNum = expiresTime - nowTimeNum;
      return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24);
    }
  }

}
</script>

<style scoped>

</style>
